package bill

import (
	"jlpay-sdk-go/pkg/jlpay/core"
	"jlpay-sdk-go/pkg/jlpay/models"
)

// ==================== 账单下载查询 ====================

// BillDownloadQueryRequest 账单下载查询请求
type BillDownloadQueryRequest struct {
	models.OrgBaseRequest
	// BillType 账单类型
	BillType string `json:"bill_type,omitempty"`
	// Dt 账单日期yyyyMMdd
	Dt string `json:"dt,omitempty"`
	// 原始请求映射数据
	rawRequestMap map[string]interface{} `json:"-"`
}

// NewBillDownloadQueryRequest 创建账单下载查询请求
func NewBillDownloadQueryRequest() *BillDownloadQueryRequest {
	req := &BillDownloadQueryRequest{}
	return req
}

// SetBillType 设置账单类型
func (r *BillDownloadQueryRequest) SetBillType(billType string) *BillDownloadQueryRequest {
	r.BillType = billType
	return r
}

// SetDt 设置账单日期yyyyMMdd
func (r *BillDownloadQueryRequest) SetDt(dt string) *BillDownloadQueryRequest {
	r.Dt = dt
	return r
}

// SetRawRequestMap 设置原始请求映射数据
func (r *BillDownloadQueryRequest) SetRawRequestMap(rawMap map[string]interface{}) *BillDownloadQueryRequest {
	r.rawRequestMap = rawMap
	return r
}

// GetRawMap 获取原始请求映射数据
func (r *BillDownloadQueryRequest) GetRawMap() (map[string]interface{}, bool) {
	return r.rawRequestMap, len(r.rawRequestMap) > 0
}

// ToMap 转换为map
func (r *BillDownloadQueryRequest) ToMap() (map[string]interface{}, error) {
	// 如果有原始请求数据，优先使用
	if rawMap, hasRaw := r.GetRawMap(); hasRaw {
		return rawMap, nil
	}

	// 先获取基类的map
	baseMap, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	// 添加自己的字段
	if r.BillType != "" {
		baseMap["bill_type"] = r.BillType
	}
	if r.Dt != "" {
		baseMap["dt"] = r.Dt
	}

	return baseMap, nil
}

// CheckRequiredParams 检查必需参数
func (r *BillDownloadQueryRequest) CheckRequiredParams(config *core.Config) error {
	// 与Python版本保持一致，不进行参数校验
	return nil
}

// BillDownloadQueryResponse 账单下载查询响应
type BillDownloadQueryResponse struct {
	models.StandardResponse
	// FileURL 文件URL
	FileURL string `json:"file_url,omitempty"`
}

// NewBillDownloadQueryResponse 创建账单下载查询响应
func NewBillDownloadQueryResponse() *BillDownloadQueryResponse {
	return &BillDownloadQueryResponse{}
}
